package com.mc.lp.database.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.CollectionUtils;

import com.mc.lp.database.dao.IDBPropertyDAO;
import com.mc.lp.database.entity.DBPropertyEntity;
import com.mc.lp.shared.vo.KeyValue;
import com.mc.lp.shared.vo.KeyValueMap;

/**
 * this DAO will loads the database properties into system
 * @author deepak
 */
public class DBPropertyDAOImpl extends AbstractGenericHibernateDAO<DBPropertyEntity, Long, IDBPropertyDAO> implements IDBPropertyDAO{
	private static final long serialVersionUID = 1L;
	
	/**
	 * returns all properties based on module and environment
	 * @param env
	 * @param moduleName
	 * @return
	 */
	public List<KeyValue> getAllPropertiesByEnvAndModule(String env, String moduleName){
		ArrayList<KeyValue> propertyList= new ArrayList<KeyValue>();
		
		//create criteria
		KeyValueMap map = new KeyValueMap().
							addKeyValue("env", env).
							addKeyValue("moduleName", moduleName);
		
		List<DBPropertyEntity> dbPropertyList=findByProperties(map);
		if(!CollectionUtils.isEmpty(dbPropertyList)){
			for(DBPropertyEntity propertyEntity:dbPropertyList){
				propertyList.add(new KeyValue(propertyEntity.getPropertyName(), propertyEntity.getPropertyValue()));
			}
		}
		return propertyList;
	}
}